<?php

  require_once "JooS/PHPackager/FS/Action/Abstract.php";

  /**
   * @property string $realPath
   * @property bool $cleanupDirectories
   */
  class JooS_PHPackager_FS_Action_Unlink extends JooS_PHPackager_FS_Action_Abstract {
    public function __invoke() {
      $dirname = dirname($this->realPath);
      unlink($this->realPath);

      if ($this->cleanupDirectories) {
        while (is_dir($dirname) && is_writable($dirname)) {
          $files = glob($dirname . "/*");
          if (!sizeof($files)) {
            rmdir($dirname);
            $dirname = dirname($dirname);
          }
          else {
            break;
          }
        }
      }
    }

    /**
     * @return JooS_PHPackager_FS_Action_Unlink
     */
    public static function newInstance() {
      return new self();
    }
  }
